# -t <image tag>  : specify image tag
# -d              : download image

#ARGPARSE SHORT t $TSET $TARG1 $TARG2
#ARGPARSE LONG imagetag $TEST $TARG1 $TARG2
#ARGPARSE SHORT d $DSET

argparse() {
	local argparse_info="$(sed -n 's/^#ARGPARSE //p' ./run_tuna.sh)"
	local vargs_short=""
	local vargs_long=""
	local is_short=false
	local is_flag=false
	for x in $argparse_info; do
		if [ $x = "SHORT" ]; then
			is_short=true
			is_flag=true
		elif [ $x = "LONG" ]; then
			is_short=false
			is_flag=true
		else
			if $is_flag; then
				if $is_short; then
					vargs_short="$vargs_short $x"
				else
					vargs_long="$vargs_long $x"
				fi
				is_flag=false
			else
				if $is_short; then
					vargs_short="$vargs_short;$x"
				else
					vargs_long="$vargs_long;$x"
				fi
			fi
		fi
	done

	echo "$vargs_short" | sed -n "/ $flag;/p"
	echo $vargs_long

	local argnum="$#"
	local optnum=0
	while [ $argnum -gt 0 ]; do
		if [ $optnum -gt 0 ]; then
			#TODO: Parse opts
			echo "This seems to be an opt"
			optnum=$(expr - 1)
		else
			local arg="$1"
			# check if arg starts with -
			if [ "${arg%${arg#?}}"x = '-x' ]; then
				echo "Yes, this is a short argument"
				if ! [ -z "$(echo "$vargs_short" | \
					sed -n "/ $(echo $arg | awk '{print substr($0,2);}');/p")" ]; then
					arg="$(echo "$arg" | awk '{print substr($0,2)}')"
					setting="$(echo "$vargs_short" | awk "match(\$0,/$arg/) { print \$NF }" |
						cut -f2 -d';')"
				fi
			fi
		fi

		shift
		argnum=$(expr $argnum - 1)
	done
}

argparse $@
